﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using zhangmenren.IService;
using zhangmenren.Models;

namespace zhangmenren.Areas.Admin.Controllers
{
	[Area(areaName: "Admin")]
	public class OrderController : ABaseController
    {
		private IOrderService orderService;
		public OrderController(IOrderService _orderService)
		{
			orderService = _orderService;
		}
        public IActionResult Index()
        {
            return View();
        }


		public async Task<string> GetOrder(string content = "",int page = 1)
		{
			int total = 0;
			IEnumerable<OrderEntity> dataList = null;
			dataList = await orderService.Select(page,50, content);
			if (dataList.Any())
			{
				total = dataList.Count();
			}
			return JsonConvert.SerializeObject(new { code = "0", msg = "查询成功", data = dataList, count = total });
		}


        [HttpPost]
        public JsonResult Del(string orderId)
        {
            if (!string.IsNullOrEmpty(orderId))
            {
                var result = orderService.Del(orderId);
                return Json(new { state = "ok", msg = "删除成功" });
            }
            return Json(new { state = "fail", msg = "标识错误" });
        }

    }
}